package com.gzq.service;

import com.gzq.entity.NewText;
import com.gzq.repository.NewTextDao;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class NewTextService {
    @Resource
    NewTextDao newTextDao;
    public List<NewText> findAll(){
        List<NewText> list= (List<NewText>) newTextDao.findAll();
        List<NewText> list1 = new ArrayList<>();
        for (NewText newText:list){
         String html=newText.getText();
         String document= Jsoup.parse(html).text();
         document= document.substring(0,70)+"<br>"+document.substring(70,100)+"...";
         newText.setText(document);
         list1.add(newText);
        }
        return list1;
    }
    public NewText findById(long id){
        return newTextDao.findOne(id);
    }
}
